<template>
  <div>
    <!-- 后台 -->
    <el-row v-if="isuser == null ? false : isuser.roles !== '顾客'" style="display: flex;align-items: flex-end;">
      <el-col :span="9" class="l-content" style="display: flex; align-items: center; margin-left: 3%;">
        <el-button icon="el-icon-menu" size="mini" @click="handleMenu" style="margin-right: 10px;"></el-button>
        <!-- 面包屑 -->
        <el-breadcrumb separator="/">
          <el-breadcrumb-item to="/HomePage" style="color: #000;">首页</el-breadcrumb-item>
          <transition-group>
            <el-breadcrumb-item v-for="(item, index) in $route.meta.headerName" :key="index">
              <router-link v-if="item.url" :to="item.url">{{ item.name }}</router-link>
              <span v-else>
                {{ item.name }}
              </span>
            </el-breadcrumb-item>
          </transition-group>
        </el-breadcrumb>
      </el-col>
      <el-col :span="12" class="r-content ">
        <div class="login_and_register " style="margin-top: 5px;">
          <weather class="wat"></weather>
          <el-dropdown>
            <div>
              <el-avatar class="el-avatar">
                <img src="@/assets/avat (2).gif" alt="默认头像" />
              </el-avatar>
            </div>
            <el-dropdown-menu class="el-dropdown-menu" slot="dropdown">
              <span style="border-top: 1px solid" @click="toHome()"><el-dropdown-item><i
                    class="el-icon-house" />首页</el-dropdown-item></span>
              <span style="border-top: 1px solid" @click="toPersonal()"><el-dropdown-item><i
                    class="el-icon-user" />个人中心</el-dropdown-item></span>
              <span style="border-top: 1px solid" @click="toChangePwd()"><el-dropdown-item><i class="el-icon-edit" />
                  修改密码</el-dropdown-item></span>
              <span style="border-top: 1px solid" @click="toMyOrder()"
                v-if="isuser.roles !== null && isuser.roles == '顾客'">
                <el-dropdown-item><i class="el-icon-document" />我的订单</el-dropdown-item>
              </span>
              <span style="border-top: 1px solid" @click="toMyCart()"
                v-if="isuser.roles !== null && isuser.roles == '顾客'">
                <el-dropdown-item><i class="el-icon-shopping-cart-full" />购物车</el-dropdown-item>
              </span>
              <span style="border-top: 1px solid" @click="exit()"><el-dropdown-item><i
                    class="el-icon-position" />退出</el-dropdown-item></span>
            </el-dropdown-menu>
          </el-dropdown>
        </div>
      </el-col>
    </el-row>
    <!-- 前台 -->
    <el-row class="nav_box " v-else>
      <el-col :span="6">
        <div class="logo">
          <a href="">
            <img src="@/assets/logo.png" alt="">
          </a>
        </div>
      </el-col>
      <el-col :span="12">
        <div class="nav">
          <a href="#/MallHome" v-bind:class="`${this.$route.path == '/MallHome' ? 'home ' : ' '}`">首页</a>
          <router-link :to="{ path: '/cake', query: { soke: '蛋糕' } }"> <a href="">蛋糕</a> </router-link>
          <router-link :to="{ path: '/cake', query: { soke: '下午茶' } }"> <a href="">下午茶</a> </router-link>
          <router-link :to="{ path: '/cake', query: { soke: '面包' } }"> <a href="">面包</a> </router-link>
       
          <a href="#/">精选食材</a>
          <a href="#/">最新活动</a>
          <a href="#/">企业专区</a>
          <a href="#/">会员中心</a>
        </div>
      </el-col>
      <el-col :span="6">
        <div class="login_and_register">
          <div v-if="isuser== null" style="text-align: right;">
            <a href="#/loginForm" class="login">登录</a>
            <a href="#/registerForm">注册</a>
          </div>
          <div class="r-content " v-else>
            <weather class="wat" style="margin-right: 3%;"></weather>
            <el-dropdown >
              <div>
                <el-avatar class="el-avatar">
                  <img src="@/assets/avat (2).gif" alt="默认头像" />
                </el-avatar>
              </div>
              <el-dropdown-menu class="el-dropdown-menu" slot="dropdown">
                <span style="border-top: 1px solid" @click="toHome()"><el-dropdown-item><i
                      class="el-icon-house" />首页</el-dropdown-item></span>
                <span style="border-top: 1px solid" @click="toPersonal()"><el-dropdown-item><i
                      class="el-icon-user" />个人中心</el-dropdown-item></span>
                <span style="border-top: 1px solid" @click="toChangePwd()"><el-dropdown-item><i class="el-icon-edit" />
                    修改密码</el-dropdown-item></span>
                <span style="border-top: 1px solid" @click="toMyOrder()"
                  v-if="isuser.roles !== null && isuser.roles == '顾客'">
                  <el-dropdown-item><i class="el-icon-document" />我的订单</el-dropdown-item>
                </span>
                <span style="border-top: 1px solid" @click="tocollect()"
                  v-if="isuser.roles !== null && isuser.roles == '顾客'">
                  <el-dropdown-item><i class="el-icon-folder-opened" />我的收藏</el-dropdown-item>
                </span>
                <span style="border-top: 1px solid" @click="toMyCart()"
                  v-if="isuser.roles !== null && isuser.roles == '顾客'">
                  <el-dropdown-item><i class="el-icon-shopping-cart-full" />购物车</el-dropdown-item>
                </span>
                <span style="border-top: 1px solid" @click="exit()"><el-dropdown-item><i
                      class="el-icon-position" />退出</el-dropdown-item></span>
              </el-dropdown-menu>
            </el-dropdown>

          </div>
        </div>
      </el-col>

    </el-row>
  </div>
</template>
<script>
import weather from '@/components/weather.vue';
export default {
  components: { weather },
  name: 'JuDuoKeCommonHeader',
  comcomponents: {
    weather
  },
  data () {
    return {
      isuser: null
    };
  },
  mounted () {
    this.isuser = JSON.parse(window.localStorage.getItem('stoken'))
  },
  methods: {
    handleMenu () {
      this.$store.commit('collapseMenu')
    },
    // 首页
    toHome () {
      if (this.isuser.roles !== null && this.isuser.roles == '顾客') {
        if (this.$route.path !== '/MallHome') {
          this.$router.push({ path: '/MallHome' });
        }
      } else {
        if (this.$route.path !== '/HomePage') {
          this.$router.push({ path: '/HomePage' });
        }
      }
    },
    // 个人中心
    toPersonal () {
      this.$router.push({ path: '/personalCenter' })
    },
    // 修改密码
    toChangePwd () {
      this.$router.push({ path: '/changePassword' })
    },
    // 我的订单
    toMyOrder () {
      this.$router.push({ path: '/myOrder' })
    },
    // 我的购物车
    toMyCart () {
      this.$router.push({ path: '/shoppingCart' })
    },
    tocollect(){
      this.$router.push({ path: '/collect' })
    },
    // 退出
    exit () {
      this.$confirm('您确定要退出吗？', '温馨提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        let loading = this.$loading({ lock: true, text: "正在退出", background: "rgba(255,255,255,0.5)" });
        setTimeout(() => {
          loading.close();
          this.$message({ showClose: true, message: '退出成功', duration: 1000, type: 'success', });
          //调转到login界面
          this.$router.replace({ path: '/loginForm' })
          localStorage.clear()
        }, 1000)
      }).catch((err) => {
        // let loading = this.$loading({ lock: true, text: "正在退出", background: "rgba(255,255,255,0.5)" });
        // setTimeout(() => {
        //   loading.close();
        // }, 1000)
      })
    }
  }
};
</script>
<style lang="scss" scoped>
.v-enter-active,
.v-leave-active {
  transition: all 1s;
}

.v-leave-active,
.v-enter {
  opacity: 0;
  transform: translateX(20px);
}

.v-leave-active {
  position: absolute;
}

// /deep/ 样式穿刺 设置的样式对所以子组件都生效，这个时候得使用 /deep/ 深度选择器。&并集

.l-content {
  display: flex;
  align-items: center;

  .el-breadcrumb {
    line-height: 10px;
    background: #FFFFFF;
    font-size: 15px;
    padding: 0 20px;
  }

  /* 被选中时的颜色 */
  .el-breadcrumb__item:last-child ::v-deep .el-breadcrumb__inner {
    color: #606266 !important;
  }
}



.header .el-dropdown {
  display: flex;
  width: 75px !important;

}

.header .el-dropdown-menu {
  padding: 0 !important;
  text-align: center;
  user-select: none;
  width: 100px;
}

.r-content {
  justify-content: flex-end;
  display: flex;
}

.nav_box {
  width: 100%;
  height: 70px;
 position: fixed;
  top: 0;
  z-index: 1111111111;
  box-shadow: none !important;
  background: #f9f9f9;
  border-bottom: 1px solid #bbbbbb;
  display: flex;
  align-items: center;
}

a {
  font-size: 15px;
  color: #3c2314 !important;
}

a:hover {
  color: #c8b49b !important;
}

.home {
  color: #c8b49b !important;
}

.logo img {
  width: 200px;
  height: 130px;
  margin-left: 16%;
margin-top: 4%;
}

.nav {

  height: 100%;
}

.nav>a {
  margin-right: 48px;
}

.login_and_register {
  width: 180px;
  height: 100%;
  display: flex;
  justify-content: flex-end;
  align-items: center;
}

.login::after {
  content: "|";
  margin-left: 10px;
  margin-right: 10px;
}
</style>